<template>
  <div style='margin-bottom: 80px;'>
    <a-divider orientation='left'>上期发货明细</a-divider>
    <f-table ref='table1' :scroll='{x:2400,y:500}' rowKey='orderDetailsId' :tableColumns='financeDetailsColumns' size='small' :showTotal='true' handler='finacePageListHandler' :autoLoad='false' :params='queryParam' :api='api.bod' :multiple='false'>
     <span slot='action' slot-scope='text, record'>
          <template>
            <a href='javascript:;' @click="updateRenkuan(record,'table1')">调账</a>
            <a-divider type='vertical' />
            <a @click='$refs.orderInfoDrawer.showDrawer(record)'>查看</a>
          </template>
        </span>
    </f-table>

    <a-divider orientation='left' v-if='orderDetailList&&orderDetailList.length>0'>本期发货明细</a-divider>
    <f-table ref='table6' style='margin-bottom: 85px' :scroll='{x:true}' v-if='orderDetailList&&orderDetailList.length>0' :showTotal='true' rowKey='orderDetailsId' :tableColumns='financeDetailsColumns' size='small' :dataSource='orderDetailList' :showPagination='false' :multiple='false'>
    <span slot='action' slot-scope='text, record'>
          <template>
            <a href='javascript:;' @click="updateRenkuan(record,'table6')">调账</a>
            <a-divider type='vertical' />
            <a @click='$refs.orderInfoDrawer.showDrawer(record)'>查看</a>
          </template>
        </span>

    </f-table>


    <a-divider orientation='left' v-if='lastReturnList&&lastReturnList.length>0'>本期回上期</a-divider>
    <f-table ref='table2' :scroll='{x:true}' style='width: 85%' v-if='lastReturnList&&lastReturnList.length>0' :showTotal='true' rowKey='orderDetailsId' :tableColumns='lastReturnColumn' size='small' :dataSource='lastReturnList' :showPagination='false' :multiple='false'>
  <span slot='action' slot-scope='text, record'>
          <template>
            <a href='javascript:;' @click="updateRenkuan(record,'table2')">调账</a>
            <a-divider type='vertical' />
            <a @click='$refs.orderInfoDrawer.showDrawer(record)'>查看</a>
          </template>
        </span>
    </f-table>

    <a-divider orientation='left' v-if='lastSettleList&&lastSettleList.length>0'>本期结算上期</a-divider>
    <f-table ref='table3' :scroll='{x:true}' style='width: 85%' v-if='lastSettleList&&lastSettleList.length>0' :showTotal='true' rowKey='orderDetailsId' :tableColumns='lastSettleColumn' size='small' :dataSource='lastSettleList' :showPagination='false' :multiple='false'>
    <span slot='action' slot-scope='text, record'>
          <template>
            <a href='javascript:;' @click="updateRenkuan(record,'table3')">调账</a>
            <a-divider type='vertical' />
            <a @click="$refs.orderInfoDrawer.showDrawer(record)">查看</a>
          </template>
        </span>
    </f-table>

    <a-divider orientation='left' v-if='lastTbList&&lastTbList.length>0'>本期退上期保证金</a-divider>
    <f-table ref='table4' :scroll='{x:true}' style='width: 85%' v-if='lastTbList&&lastTbList.length>0' :showTotal='true' rowKey='orderDetailsId' :tableColumns='lastTbColumn' size='small' :dataSource='lastTbList' :showPagination='false' :multiple='false'>
   <span slot='action' slot-scope='text, record'>
          <template>
            <a href='javascript:;' @click="updateRenkuan(record,'table4')">调账</a>
            <a-divider type='vertical' />
            <a @click="$refs.orderInfoDrawer.showDrawer(record)">查看</a>
          </template>
        </span>
    </f-table>

    <a-modal title='调整认款月份' :visible='renkuanModal' width='500px' @cancel='renkuanCancel' @ok='renkuanSubmit'>
      <f-form ref='form' :action='api.bod.updateRenkuan' :form-key='this.formItem.orderDetailsId'>
        <f-form-item label='认款月份' type='month' name='renkuanDate' :value='formItem.renkuanDate' />
      </f-form>
    </a-modal>
    <order-info-drawer ref='orderInfoDrawer'></order-info-drawer>
  </div>
</template>
<script>

import api from "./js/api"
import OrderInfoDrawer from "@/views/module/business/order/order_info_drawer"

export default {
  name: "financeDetails",
  components: { OrderInfoDrawer },
  data() {
    return {
      api: Object.assign(api, this.api),
      disabled: false,
      renkuanModal: false,
      //列表初始化查询参数
      queryParam: {
        deptId: ""
      },
      tableName:'',
      orderDetailList: [],
      lastReturnList: [],
      lastSettleList: [],
      lastTbList: [],
      financeDetailsColumns: [
        {
          title: "操作",
          align: "left",
          width: 80,
          dataIndex: "action",
          scopedSlots: { customRender: "action" }
        },
        {
          title: "单号",
          align: "left",
          width: "100px",
          dataIndex: "orderNo"
        },
        {
          title: "发货日期",
          align: "left",
          width: 60,

          dataIndex: "saleDate"
        },
        {
          title: "购货方",
          align: "left",
          width: 130,
          ellipsis: true,
          dataIndex: "customName"
        },
        {
          title: "商品名称",
          align: "left",
          width: 130,
          ellipsis: true,
          dataIndex: "drugsName"
        }, {
          title: "规格",
          align: "left",
          width: 60,
          dataIndex: "drugsSpec"
        }, {
          title: "数量",
          align: "left",
          width: 60,
          dataIndex: "saleNum"
        }, {
          title: "单价",
          align: "left",
          width: 50,
          dataIndex: "salePrice"
        }, {
          title: "发货金额",
          align: "left",
          width: 60,
          needTotal: true,
          dataIndex: "saleAmount"
        }, {
          title: "回款金额",
          align: "left",
          width: 60,
          needTotal: true,
          dataIndex: "returnAmount"
        }, {
          title: "回款日期",
          align: "left",
          width: 60,
          dataIndex: "returnDate"
        }, {
          title: "认款月份",
          align: "left",
          width: 60,
          dataIndex: "renkuanDate"
        }, {
          title: "资保金收款",
          align: "left",
          width: 60,
          needTotal: true,
          dataIndex: "customBondAmount"
        }, {
          title: "收款日期",
          align: "left",
          width: 60,
          dataIndex: "takeDate"
        }, {
          title: "资保金退款",
          align: "left",
          width: 60,
          needTotal: true,
          dataIndex: "returnCustomBond"
        }, {
          title: "退款日期",
          align: "left",
          width: 60,
          dataIndex: "returnCustomBondDate"
        }, {
          title: "应付结算",
          align: "left",
          width: 60,
          needTotal: true,
          dataIndex: "settleAmount"
        }, {
          title: "已付结算",
          align: "left",
          width: 60,
          needTotal: true,
          dataIndex: "settleRealAmount"
        }, {
          title: "结算日期",
          align: "left",
          width: 70,
          dataIndex: "settlePayDate"
        }, {
          title: "应付结算2",
          align: "left",
          width: 60,
          needTotal: true,
          dataIndex: "settleAmount2"
        }, {
          title: "已付结算2",
          align: "left",
          width: 60,
          needTotal: true,
          dataIndex: "settleRealAmount2"
        }, {
          title: "结算日期2",
          align: "left",
          width: 60,
          dataIndex: "settlePayDate2"
        }, {
          title: "已结算总金额",
          align: "left",
          needTotal: true,
          width: 70,
          dataIndex: "yesSettleAmount"
        }, {
          title: "未结算金额",
          align: "left",
          needTotal: true,
          width: 60,
          dataIndex: "noSettleAmount"
        }, {
          title: "批号",
          align: "left",
          width: 60,
          dataIndex: "drugsLotNo"
        }
      ],
      lastReturnColumn: [
        {
          title: "操作",
          align: "left",
          dataIndex: "action",
          width: 80,
          scopedSlots: { customRender: "action" }
        },
        {
          title: "单号",
          align: "left",
          width: "100px",
          dataIndex: "orderNo"
        },
        {
          title: "发货日期",
          align: "left",
          width: 60,
          dataIndex: "saleDate"
        },
        {
          title: "购货方",
          align: "left",
          width: 130,
          ellipsis: true,
          dataIndex: "customName"
        },
        {
          title: "商品名称",
          align: "left",
          width: 130,
          ellipsis: true,
          dataIndex: "drugsName"
        }, {
          title: "规格",
          align: "left",
          width: 60,
          dataIndex: "drugsSpec"
        }, {
          title: "数量",
          align: "left",
          width: 60,
          dataIndex: "saleNum"
        }, {
          title: "单价",
          align: "left",
          width: 50,
          dataIndex: "salePrice"
        }, {
          title: "发货金额",
          align: "left",
          width: 60,
          needTotal: true,
          dataIndex: "saleAmount"
        }, {
          title: "回款金额",
          align: "left",
          width: 60,
          needTotal: true,
          dataIndex: "returnAmount"
        }, {
          title: "回款日期",
          align: "left",
          width: 60,
          dataIndex: "returnDate"
        }, {
          title: "认款月份",
          align: "left",
          width: 60,
          dataIndex: "renkuanDate"
        }
      ],
      lastSettleColumn: [
        {
          title: "操作",
          align: "left",
          width: 80,
          dataIndex: "action",
          scopedSlots: { customRender: "action" }
        },
        {
          title: "单号",
          align: "left",
          width: "100px",
          dataIndex: "orderNo"
        },
        {
          title: "发货日期",
          align: "left",
          width: 60,
          dataIndex: "saleDate"
        },
        {
          title: "购货方",
          align: "left",
          width: 130,
          ellipsis: true,
          dataIndex: "customName"
        },
        {
          title: "商品名称",
          align: "left",
          width: 130,
          ellipsis: true,
          dataIndex: "drugsName"
        }, {
          title: "规格",
          align: "left",
          width: 60,
          dataIndex: "drugsSpec"
        }, {
          title: "数量",
          align: "left",
          width: 60,
          dataIndex: "saleNum"
        }, {
          title: "单价",
          align: "left",
          width: 50,
          dataIndex: "salePrice"
        }, {
          title: "发货金额",
          align: "left",
          width: 60,
          needTotal: true,
          dataIndex: "saleAmount"
        }, {
          title: "应付结算",
          align: "left",
          width: 60,
          needTotal: true,
          dataIndex: "settleAmount"
        }, {
          title: "已付结算",
          align: "left",
          width: 60,
          needTotal: true,
          dataIndex: "settleRealAmount"
        }, {
          title: "结算日期",
          align: "left",
          width: 70,
          dataIndex: "settlePayDate"
        }, {
          title: "应付结算2",
          align: "left",
          width: 60,
          needTotal: true,
          dataIndex: "settleAmount2"
        }, {
          title: "已付结算2",
          align: "left",
          width: 60,
          needTotal: true,
          dataIndex: "settleRealAmount2"
        }, {
          title: "结算日期2",
          align: "left",
          width: 60,
          dataIndex: "settlePayDate2"
        }
      ],
      lastTbColumn: [
        {
          title: "操作",
          align: "left",
          dataIndex: "action",
          width: 80,
          scopedSlots: { customRender: "action" }
        },
        {
          title: "单号",
          align: "left",
          width: "100px",
          dataIndex: "orderNo"
        },
        {
          title: "发货日期",
          align: "left",
          width: 60,
          dataIndex: "saleDate"
        },
        {
          title: "购货方",
          align: "left",
          width: 130,
          ellipsis: true,
          dataIndex: "customName"
        },
        {
          title: "商品名称",
          align: "left",
          width: 130,
          ellipsis: true,
          dataIndex: "drugsName"
        }, {
          title: "规格",
          align: "left",
          width: 60,
          dataIndex: "drugsSpec"
        }, {
          title: "数量",
          align: "left",
          width: 60,
          dataIndex: "saleNum"
        }, {
          title: "单价",
          align: "left",
          width: 50,
          dataIndex: "salePrice"
        }, {
          title: "发货金额",
          align: "left",
          width: 60,
          needTotal: true,
          dataIndex: "saleAmount"
        }, {
          title: "退款金额",
          align: "left",
          width: 60,
          needTotal: true,
          dataIndex: "returnAmount"
        }, {
          title: "退款日期",
          align: "left",
          width: 60,
          dataIndex: "returnDate"
        }
      ],
      formItem: this.getFormItem(),
      saleManForm: {}
    }
  },
  created() {
  },
  methods: {
    getFormItem() {
      return {
        settleId: "",
        deptId: "",
        bankId: null,
        selectIds: "",
        amount: 0,
        settleType: 1,
        amountDate: "",
        remark: ""
      }
    },
    setData(data) {
      if (data && data.financeId) {
        this.queryParam.financeId = data.financeId
        //查询已结算明细
        this.http.get(this, {
          url: this.api.bfd.list,
          params: {
            financeId: data.financeId
          },
          success: function(me, data) {
            me.orderDetailList = data.orderDetailList
            me.lastSettleList = data.lastSettleList
            me.lastReturnList = data.lastReturnList
            me.$refs["table1"].refresh(false)
          }
        })
      }
    },
    updateRenkuan(record,tableName) {
      this.formItem = record
      this.tableName=tableName;
      this.renkuanModal = true
    },
    renkuanCancel() {
      this.renkuanModal = false
    },
    renkuanSubmit() {
      this.$refs.form.submit({
        orderDetailsId: this.formItem.orderDetailsId
      }, () => {
        this.$refs[this.tableName].refresh(false)
        this.renkuanCancel()
      })
    }
  }
}
</script>
